package com.fyp.ptma.dao.service;

import java.util.List;

import javax.persistence.PersistenceException;

import org.hibernate.HibernateException;
import org.hibernate.exception.ConstraintViolationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.fyp.ptma.dao.repository.irepository.IDefectDao;
import com.fyp.ptma.dao.service.iservice.IDefectService;
import com.fyp.ptma.model.Application;
import com.fyp.ptma.model.ApplicationVersion;
import com.fyp.ptma.model.Defect;

/**
 * 
 * @author YahyaArshad
 * 
 */
@Service
public class DefectService implements IDefectService {

	@Autowired
	private IDefectDao defectDao;

	@Transactional
	public Long save(Object objToSave) throws PersistenceException,
			ConstraintViolationException {
		// TODO Auto-generated method stub

		Long id = defectDao.save(objToSave);
		return id;
	}

	@Transactional
	public Long update(Object objToUpdate) throws PersistenceException {
		// TODO Auto-generated method stub
		return defectDao.update(objToUpdate);
	}

	@Transactional
	public boolean delete(Object objToDelete) throws PersistenceException,
			ConstraintViolationException {
		// TODO Auto-generated method stub
		return defectDao.delete(objToDelete);
	}

	@Transactional
	public List<Defect> getDefectsByApplicationVersion(
			ApplicationVersion version) throws HibernateException {
		// TODO Auto-generated method stub
		return defectDao.getDefectsByApplicationVersion(version);
	}

	@Transactional
	public List<Defect> getDefectsByApplication(Application application)
			throws HibernateException {
		// TODO Auto-generated method stub
		return defectDao.getDefectsByApplication(application);
	}

	@Transactional
	public List<Defect> getDownloaderDefects(Application application)
			throws HibernateException {
		// TODO Auto-generated method stub
		return defectDao.getDownloaderDefects(application);
	}

	@Transactional
	public List<Defect> getUserDefects(Application application)
			throws HibernateException {
		// TODO Auto-generated method stub
		return defectDao.getUserDefects(application);
	}

	@Transactional
	public void saveOrUpdate(Object objToSave) throws PersistenceException,
			ConstraintViolationException {
		defectDao.saveOrUpdate(objToSave);

	}

}
